package com.wdh.networklibrary.mvp.base.activity;


import androidx.appcompat.app.AppCompatActivity;
import com.wdh.networklibrary.mvp.presenter.BasePresenter;
import com.wdh.networklibrary.mvp.view.BaseView;

/**
 * Mvp BaseActivity
 *
 * @param <P>
 */
abstract public class MVPActivity<P extends BasePresenter> extends AppCompatActivity
        implements BaseView {

    private P mPresenter;

    /**
     * 底层获取P
     *
     * @return P
     */
    protected synchronized P getP() {
        if (mPresenter == null) {
            mPresenter = createPresenter();
        }
        return mPresenter;
    }


    /**
     * 创建Presenter
     *
     * @return 返回Presenter的实例
     */
    protected abstract P createPresenter();

    @Override
    public void onComplete() {
        // 请求完成、关闭dialog
      //  dismissDialog();
    }

//
//    public void onDialogCancelListener(AlertDialog dialog) {
//        // dialog取消，取消订阅
//        getP().unDisposable();
//    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        // 销毁 取消订阅
        getP().unDisposable();
    }

    @Override
    public void onFailure(String message) {
//        showWarningDialog(message);
        // 统一错误管理
    }
}
